/**   
* @Title: DaiZhongYwView.java 
* @Package com.zjdiepu.www.manage.api.zpp.view 
* 
* @author zhangpp
* @date 2017年5月27日 上午10:06:48 
* @version V1.0   
*/
package com.zjdiepu.www.manage.api.zpp.view;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.zjdiepu.www.base.enums.type.DataDicType;
import com.zjdiepu.www.base.enums.type.ResultFlagType;
import com.zjdiepu.www.common.util.DateUtil;
import com.zjdiepu.www.common.util.UUIDFactory;
import com.zjdiepu.www.commpent.ViewScopeControllerHelper;
import com.zjdiepu.www.dao.yw.YwBusinessMapper;
import com.zjdiepu.www.ibiz.cache.ICachedDictionaryService;
import com.zjdiepu.www.ibiz.zpp.PublicService;
import com.zjdiepu.www.model.yw.dto.YwBusiness;
import com.zjdiepu.www.model.yw.dto.YwBusinessCar;
import com.zjdiepu.www.model.yw.response.YwBusinessDetail;
import com.zjdiepu.www.util.ExceptionHelper;



/**      
 * 项目名称：diepu-parent-manage   
 * 类名称：DaiZhongYwView   
 * 类描述：   
 * 创建人：zhangpp
 * 创建时间：2017年5月27日 上午10:06:48   
 * 修改人：zhangpp
 * 修改时间：2017年5月27日 上午10:06:48   
 * 修改备注：   
 * @version V1.0     
 */
@Controller
@RequestMapping(value= "DaiZhongYwView", produces="application/json;charset=UTF-8")
@Api(tags = {"作者：张鹏鹏，电话：15158822934"}, produces="application/json;charset=UTF-8")
public class DaiZhongYwView 
{

	@Resource
    private ViewScopeControllerHelper viewScopeControllerHelper;
	
	@Resource
    private ICachedDictionaryService cachedDictionaryService;
	
	@Resource
	private PublicService publicService;
	
	@Resource
	private YwBusinessMapper ywBusinessMapper;
	
	
	@ApiOperation(value = "贷中业务/抵押信息登记", response = Boolean.class, httpMethod="GET", tags={"贷中业务/抵押信息登记"})
    @RequestMapping(value = "daiZhongYwDiYaQueRenView", method = RequestMethod.GET)
    public String daiZhongYwDiYaQueRenView(Model model,String busiId) {
		if (StringUtils.isBlank(busiId)) {
			ExceptionHelper.thow(ResultFlagType.PARAM_EMPTY);
		}
    	model.addAttribute("carCategoryType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_CATEGORY,"请选择..."));
    	model.addAttribute("carColorType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_COLOR,"请选择..."));
    	
    	viewScopeControllerHelper.preparedNowTime(model);
    	YwBusinessDetail ywBusinessDetail = viewScopeControllerHelper.preparedBusiness(busiId, model);
    	YwBusinessCar car = viewScopeControllerHelper.preparedCar(busiId, null,model);
    	if(car != null) {
    		viewScopeControllerHelper.preparedLoan(busiId, car.getId(), model,car.getCarType());
    	}
    	if(ywBusinessDetail != null) {
    		viewScopeControllerHelper.preparedHistoryBusiness(ywBusinessDetail.getCustomerNo(), model);
    	}
    	viewScopeControllerHelper.preparedRegin(model,null,null);
    	viewScopeControllerHelper.preparedCarModel(model);
    	viewScopeControllerHelper.preparedAttachmentEnum(model);
    	
    	//车辆信息
    	String sqlXmls = "SELECT t.id,t.dvm,t.date_registration_first,t.license_plate,t.registration_number,t.area_registration,t.date_registration_now,t.remarks,cit.city_name registration_area FROM dz_registration t left join juhe_city cit on cit.city_id = t.area_registration WHERE 1 = 1 AND t.dp_status = 1 AND t.busi_id = '"+busiId+"' LIMIT 1 ";
    	List<Map<String, String>> businessCar = publicService.queryWhereSql(sqlXmls);
    	
    	YwBusiness ywBusiness = new YwBusiness();
    	ywBusiness.setId(busiId);
    	ywBusiness.setDpStatus(1);
    	ywBusiness = ywBusinessMapper.selectRefined(ywBusiness);
    	String timeLending = "";
    	if(null != ywBusiness)
    	{
    		if(null != ywBusiness.getTimeLending())
    		{
    			timeLending = DateUtil.dateTo14String(ywBusiness.getTimeLending());
    		}
    	}
    	
    	model.addAttribute("timeLending", timeLending);
    	model.addAttribute("businessCar", businessCar);
		model.addAttribute("busiId", busiId);
		model.addAttribute("uuid", UUIDFactory.getUUID());
		
    	return "daiZhongYw/mortgageRegistration";
    }
	
	@ApiOperation(value = "贷中业务/抵押确认", response = Boolean.class, httpMethod="GET", tags={"贷中业务/抵押确认"})
    @RequestMapping(value = "daiZhongYwDiYaQueRenSureView", method = RequestMethod.GET)
    public String daiZhongYwDiYaQueRenSureView(Model model,String busiId) {
		if (StringUtils.isBlank(busiId)) {
			ExceptionHelper.thow(ResultFlagType.PARAM_EMPTY);
		}
    	model.addAttribute("carCategoryType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_CATEGORY,"请选择..."));
    	model.addAttribute("carColorType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_COLOR,"请选择..."));
    	
    	viewScopeControllerHelper.preparedNowTime(model);
    	YwBusinessDetail ywBusinessDetail = viewScopeControllerHelper.preparedBusiness(busiId, model);
    	YwBusinessCar car = viewScopeControllerHelper.preparedCar(busiId, null,model);
    	if(car != null) {
    		viewScopeControllerHelper.preparedLoan(busiId, car.getId(), model,car.getCarType());
    	}
    	if(ywBusinessDetail != null) {
    		viewScopeControllerHelper.preparedHistoryBusiness(ywBusinessDetail.getCustomerNo(), model);
    	}
    	viewScopeControllerHelper.preparedRegin(model,null,null);
    	viewScopeControllerHelper.preparedCarModel(model);
    	viewScopeControllerHelper.preparedAttachmentEnum(model);
    	
    	//车辆信息
    	String sqlXmls = "SELECT t.id,t.dvm,t.date_registration_first,t.license_plate,t.registration_number,t.area_registration,t.date_registration_now,t.remarks,cit.city_name registration_area FROM dz_registration t left join juhe_city cit on cit.city_id = t.area_registration WHERE 1 = 1 AND t.dp_status = 1 AND t.busi_id = '"+busiId+"' LIMIT 1 ";
    	List<Map<String, String>> businessCar = publicService.queryWhereSql(sqlXmls);
    	
    	YwBusiness ywBusiness = new YwBusiness();
    	ywBusiness.setId(busiId);
    	ywBusiness.setDpStatus(1);
    	ywBusiness = ywBusinessMapper.selectRefined(ywBusiness);
    	String timeLending = "";
    	if(null != ywBusiness)
    	{
    		if(null != ywBusiness.getTimeLending())
    		{
    			timeLending = DateUtil.dateTo14String(ywBusiness.getTimeLending());
    		}
    	}
    	
    	model.addAttribute("timeLending", timeLending);
    	model.addAttribute("businessCar", businessCar);
		model.addAttribute("busiId", busiId);
		model.addAttribute("uuid", UUIDFactory.getUUID());
		
    	return "daiZhongYw/mortgageRegistrationSure";
    }
	
	/**
	* 贷中业务/退贷表
	* @author zhangpp
	* @Title: getDaiHouYewwKeHuShenQTYaJinListView 
	* 
	* @param @param model
	* @param @param id
	* @param @return    设定文件 
	* @return String    返回类型 
	* @version V1.0
	* @throws
	 */
	@ApiOperation(value = "带中业务/退贷表", response = Boolean.class, httpMethod="GET", tags={"带中业务/退贷表"})
    @RequestMapping(value = "getDaiHouYewwKeHuShenQTYaJinList", method = RequestMethod.GET)
    public String getDaiHouYewwKeHuShenQTYaJinListView(Model model,String id) 
	{
		if (StringUtils.isBlank(id))
		{
			ExceptionHelper.thow(ResultFlagType.PARAM_EMPTY);
		}
		
    	model.addAttribute("carCategoryType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_CATEGORY,"请选择..."));
    	model.addAttribute("carColorType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_COLOR,"请选择..."));
    	
    	viewScopeControllerHelper.preparedNowTime(model);
    	YwBusinessDetail ywBusinessDetail = viewScopeControllerHelper.preparedBusiness(id, model);
    	YwBusinessCar car = viewScopeControllerHelper.preparedCar(id, null,model);
    	if(car != null) 
    	{
    		viewScopeControllerHelper.preparedLoan(id, car.getId(), model, car.getCarType());
    	}
    	if(ywBusinessDetail != null) 
    	{
    		viewScopeControllerHelper.preparedHistoryBusiness(ywBusinessDetail.getCustomerNo(), model);
    	}
    	viewScopeControllerHelper.preparedRegin(model,null,null);
    	viewScopeControllerHelper.preparedCarModel(model);
    	viewScopeControllerHelper.preparedAttachmentEnum(model);
		
		model.addAttribute("id", id);
		model.addAttribute("uuid", UUIDFactory.getUUID());
		
    	return "daiZhongYw/returnGoods";
    }
	
	
	/**
	* 贷中业务/贷中信息登记/银行放款
	* @author zhangpp
	* @Title: getBankFangKuanListView 
	* 
	* @param @param model
	* @param @param id
	* @param @return    设定文件 
	* @return String    返回类型 
	* @version V1.0
	* @throws
	 */
	@ApiOperation(value = "贷中业务/贷中信息登记/银行放款", response = Boolean.class, httpMethod="GET", tags={"贷中业务/贷中信息登记/银行放款"})
    @RequestMapping(value = "getBankFangKuanListView", method = RequestMethod.GET)
    public String getBankFangKuanListView(Model model,String busiId) 
	{
		
		if (StringUtils.isBlank(busiId)) {
			ExceptionHelper.thow(ResultFlagType.PARAM_EMPTY);
		}
    	model.addAttribute("carCategoryType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_CATEGORY,"请选择..."));
    	model.addAttribute("carColorType", cachedDictionaryService.getValueNamesWithSpaceOption(DataDicType.CAR_COLOR,"请选择..."));
    	
    	viewScopeControllerHelper.preparedNowTime(model);
    	YwBusinessDetail ywBusinessDetail = viewScopeControllerHelper.preparedBusiness(busiId, model);
    	YwBusinessCar car = viewScopeControllerHelper.preparedCar(busiId, null,model);
    	if(car != null) {
    		viewScopeControllerHelper.preparedLoan(busiId, car.getId(), model,car.getCarType());
    	}
    	if(ywBusinessDetail != null) {
    		viewScopeControllerHelper.preparedHistoryBusiness(ywBusinessDetail.getCustomerNo(), model);
    	}
    	viewScopeControllerHelper.preparedRegin(model,null,null);
    	viewScopeControllerHelper.preparedCarModel(model);
    	viewScopeControllerHelper.preparedAttachmentEnum(model);
		
		model.addAttribute("id", busiId);
		model.addAttribute("uuid", UUIDFactory.getUUID());
			
    	return "daiZhongYw/DaiZhongXinXDengJi/bankfangkuan";
    }
}
